package com.broadsoft.platform.wfengine.runtime.nodehandler;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.broadsoft.platform.wfengine.NodeType;
import com.broadsoft.platform.wfengine.parser.ParsedWorkflowDefinition;
import com.broadsoft.platform.wfengine.runtime.WfContext;
/**
 * 
* FIXME: <A few lines of description of what class is about and what it does.> 
*
* <HR/><B>Modification Block</B>
* <P>
* Version: FIXME: 1.0.1 <BR>
* Author: FIXME: luzhen
* Date: 2011-9-16
* TAG: <A short name to find out all changed made by this modification.>
* Comments: Created.
* Bug fix NO.: <If required>
* </P>
* <P>
* ... Other Modifications following above structure.
* </P>
*
 */
public class EndNodeExecutionHandler implements INodeExecutionHandler {

    private final static Logger logger = LoggerFactory.getLogger(EndNodeExecutionHandler.class);

    public EndNodeExecutionHandler(ParsedWorkflowDefinition parsedWorkflowInfo){
        this.parsedWorkflowInfo=parsedWorkflowInfo; 
        
    }
    
    @Override
    public NodeType executeNode(NodeType currentNode, WfContext flowContext) {
        if (logger.isTraceEnabled()) {
            logger.trace("The method[executeEndNode] begin");
        }
        NodeType nextNodeType=null;
//        WfContext parentWfContext=flowContext.getParentWfContext();
//        if(null!=parentWfContext){
//            NodeType previousNodeType=parentWfContext.getPreviousNode();
//            String destNodeName=previousNodeType.getDestNode().get(0);
//            String flowName=parentWfContext.getWorkflowType().getName();
//            nextNodeType=parsedWorkflowInfo.getNodeTypeByName(flowName, destNodeName);
//        }else{
//            if (logger.isTraceEnabled()) {
//                logger.trace("This is a end node. The flow will be ended.");
//            }
//        }
        flowContext.setPreviousNode(currentNode);
        if (logger.isTraceEnabled()) {
            logger.trace("The method[executeEndNode] end");
        }
        return nextNodeType;
    }

    private ParsedWorkflowDefinition parsedWorkflowInfo;

    public ParsedWorkflowDefinition getParsedWorkflowInfo() {
        return parsedWorkflowInfo;
    }

    public void setParsedWorkflowInfo(ParsedWorkflowDefinition parsedWorkflowInfo) {
        this.parsedWorkflowInfo = parsedWorkflowInfo;
    }
}
